<template>
  <div class="purchase-order-inquire-container page-main">
    <query-page
      v-model:selectedKeys="selectedKeys"
      title="采购订单查询"
      :form-component-config="formComponentConfig"
      :form-render-config="formRenderConfig"
      :form-render-keys="formRenderKeys"
      :table-component-config="tableComponentConfig"
      :table-render-config="tableRenderConfig"
      :table-render-keys="tableRenderKeys"
      :loading="isLoading"
      :data="renderData"
      :total="total"
      @selection-change="selectionChange"
      @query-data="getData"
    />
  </div>
</template>

<script lang="ts" setup>
  import { ref, onMounted } from 'vue';
  import queryPage from '@/common/components/query-page/index.vue';
  import {
    formRenderConfig,
    formComponentConfig,
  } from '@/views/purchase-order/components/formComp/baseFormConfig';
  import {
    tableRenderConfig,
    tableComponentConfig,
  } from '@/views/purchase-order/components/tableComp/baseTableConfig';
  import { getPmsOrderPage } from '@/api/purchase-order/purchaseOrderPreparation';
  import { baseRenderData } from './baseRenderData';

  const selectedKeys = ref([]);
  const isLoading = ref(true);
  const renderData = ref<any[]>([]);
  const total = ref(0);
  // 渲染检索项
  const formRenderKeys = ref<any[]>([...baseRenderData.formRenderKeys]);

  // 当前表格要渲染哪些值
  const tableRenderKeys = ref<any[]>([...baseRenderData.tableRenderKeys]);
  const getData = async (queryInfo: object) => {
    renderData.value = [];
    isLoading.value = true;
    const param = { ...queryInfo } as any;
    if (param.editDatetimeStart || param.editDatetimeEnd) {
      param.editDatetime = `${
        param.editDatetimeStart ? `${param.editDatetimeStart} 00:00:00` : ''
      },${param.editDatetimeEnd ? `${param.editDatetimeEnd} 23:59:59` : ''}`;
    }
    console.log('queryInfo', queryInfo);
    const res: any = await getPmsOrderPage(queryInfo);
    if (res.code === 200) {
      total.value = res.data.total;
      renderData.value = res.data.list.map((item: any) => {
        item.isEidt = false;
        return item;
      });
    }
    isLoading.value = false;
  };
  const selectionChange = (val: string[]) => {
    console.log('selectedKeys', val);
  };
  // 初期话
  const initData = () => {
    console.log('rowBtnList.value');
  };
  onMounted(() => {
    initData();
  });
</script>

<style lang="less" scoped>
  .purchase-order-inquire-container {
    height: calc(100vh - 125px);
  }
</style>
